#include "DynamicArray.h"
#include <stdio.h>
#include <stdlib.h>
void InitDArry(DArray * da)
{
    da->size = 10;
    da->a = (ElementType*)malloc(sizeof(ElementType) * da->size);
    if(da->a == NULL)
    {
        printf("malloc error!\n");
        return ;
    }
    da->len = 0;
}

void InsertTail(DArray * da,ElementType element)
{   
    //数组满了
    if(da->len == da->size)
    {
        da->size *=2;
        ElementType *newP = (ElementType *)malloc(sizeof(ElementType) * da->size);
       if(newP == NULL) 
        {
            printf("malloc error!\n");
            return;
        }
        for(int i=0;i< da->len;i++)
        {
            newP[i] = da->a[i];
        }
        free(da->a);
        da->a = newP;
    }
    da->a[da->len] = element;
    da->len++;
    
}

void PrintDArray(DArray * da) 
{
    printf("len = %d size = %d\n",da->len,da->size);
    for(int i = 0;i < da->len;i++)
    {
        printf("%d ",da->a[i]);
    }
    printf("\n");
}